<%@Page Language="VB" %>
<%@Import Namespace="System.XML" %>
<html><head>
<title>Accessing an XML document with an XMLTextReader object</title>
</head>
<body bgcolor="#ffffff">
<span class="heading">Accessing an XML document 
with an XMLTextReader object</span><hr />
<div id="outDocURL" runat="server"></div>
<div id="outError" runat="server">&nbsp;</div>
<div id="outResults" runat="server"></div>

<script language="vb" runat="server">

Sub Page_Load(sender As Object, e As EventArgs)

   Dim strCurrentPath As String = Request.PhysicalPath
   Dim strXMLPath As String = Left(strCurrentPath, InStrRev(strCurrentPath, "\")) & "booklist.xml"

   Dim objXMLReader As XmlTextReader

   Try

      objXMLReader = New XmlTextReader(strXMLPath)
      outDocURL.innerHTML = "Opened file: <b>" & strXMLPath & "</b>"

   Catch objError As Exception

      outError.innerHTML = "<b>* Error while accessing document</b>.<br />" _
          & objError.Message & "<br />" & objError.Source
      Exit Sub  ' and stop execution

   End Try

  
   Dim strNodeResult As String = ""
   Dim objNodeType As XmlNodeType

   Do While objXMLReader.Read()

      objNodeType = objXMLReader.NodeType

      Select Case objNodeType

        Case XmlNodeType.XmlDeclaration:
           strNodeResult += "XML Declaration: <b>" & objXMLReader.Name _
                         & " " & objXMLReader.Value & "</b><br />"

        Case XmlNodeType.Element:
           strNodeResult += "Element: <b>" & objXMLReader.Name & "</b><br />"

        Case XmlNodeType.Text:
           strNodeResult += "&nbsp; - Value: <b>" & objXMLReader.Value _
                         & "</b><br />"

      End Select

      If objXMLReader.AttributeCount > 0 Then
         Do While objXMLReader.MoveToNextAttribute()

            strNodeResult +=  "&nbsp; - Attribute: <b>" & objXMLReader.Name _
                          & "</b> &nbsp; Value: <b>" & objXMLReader.Value _
                          & "</b><br />"
         Loop

      End If

   Loop
   objXMLReader.Close()
   outResults.innerHTML = strNodeResult
End Sub
</script>
</body>
</html>
